/*
 * @Descripttion:
 * @version:
 * @Author: hujianli
 * @Date: 2022-07-03 16:06:52
 * @LastEditors: hujianli
 * @LastEditTime: 2022-07-03 16:14:00
 */
package main

import (
	"fmt"
	"time"
)

func sendLetters(channel chan string) {
	time.Sleep(time.Second)
	channel <- "a"
	time.Sleep(time.Second)
	channel <- "b"
	time.Sleep(time.Second)
	channel <- "c"
	time.Sleep(time.Second)
	channel <- "d"
}

func main() {
	fmt.Println(time.Now())
	// channel1 := make(chan string, 1) // 总共花费了7s
	channel1 := make(chan string, 3) // 总共花费了5s
	go sendLetters(channel1)
	time.Sleep(time.Second * 5) // 让主进程休眠5s
	fmt.Println(<-channel1, time.Now())
	fmt.Println(<-channel1, time.Now())
	fmt.Println(<-channel1, time.Now())
	fmt.Println(<-channel1, time.Now())
	fmt.Println(time.Now())
}
